#ifndef ITEM_MANAGER_H
#define ITEM_MANAGER_H
#include <qlist.h>
#include "Def.h"

template<class T>
class ItemManager
{
public:
	virtual ~ItemManager()
	{
	}

public:
	virtual void appendChild(T* item)
	{
		if(item)
		    children.append(item);
	}

	virtual void insertChild(int pos,T* item)
	{
	    if(pos >= 0 && item)
			children.insert(pos,item);
	}

	virtual int indexOfChild(T *item)
	{
	    if(item)
			return children.indexOf(item);
		return -1;
	}

	virtual T* findChild(int pos)
	{
	    if(pos > 0 && pos < children.size())
			return children[pos];
		return nullptr;
	}

	virtual void removeChild(int pos)
	{
	    children.removeAt(pos);
	}

	virtual void removeChild(T* item)
	{
	    children.removeOne(item);
	}

	int countOfChild()const
	{
	    return children.size();
	}
private:
	QList<T*> children;
};

#endif